package com.honey.mybatis.generator.dao.field;

import com.honey.compilation.java.Decoration;
import com.honey.compilation.java.JavaVisibility;
import com.honey.core.dbmapping.introspect.IntrospectSchema;
import com.honey.core.dbmapping.introspect.IntrospectSchemaColumn;
import com.honey.core.dbmapping.structure.Column;
import com.honey.core.dbmapping.structure.TableColumn;
import com.honey.core.utils.StringUtility;
import com.honey.mybatis.generator.AbstractField;
import com.honey.mybatis.generator.MybatisPlugin;
import com.honey.mybatis.generator.dao.DaoConstant;

public class VirtualDeleteByDynamicField extends AbstractField {
	
	private static final String[] JAVA_DOC = new String[]{
		"动态条虚拟删除。"
	};
	
	boolean enable = false ;
	public VirtualDeleteByDynamicField(
			MybatisPlugin belongPlugin,
			IntrospectSchema introspectSchema,
			IntrospectSchemaColumn introspectSchemaColumn
			) {
		if( belongPlugin.isEnableVirtualDeleteKey()){
			for(Column column : introspectSchemaColumn.allColumns() ){
				String value = ((TableColumn)column).getVirtualDeleteValue();
				if( StringUtility.stringHasValue(value)){
					enable = true;
					break;
				}
			}
		}
	}
	
	@Override
	protected String getFieldName() {
		String answer =null ;
		if( enable ){
			answer = DaoConstant.VIRTUAL_DELETE_BY_DYNAMIC_FIELD_NAME;
		}
		return answer;
	}

	/* (non-Javadoc)
	 * @see com.honey.mybatis.generator.AbstractField#getDecoration()
	 */
	@Override
	protected Decoration getDecoration() {
		Decoration answer = super.getDecoration();
		answer.setVisibility(JavaVisibility.PRIVATE);
		answer.setFinal(true);
		answer.setStatic(true);
		return answer;
	}

	/* (non-Javadoc)
	 * @see com.honey.mybatis.generator.AbstractField#getInitialization()
	 */
	@Override
	protected String getInitialization() {
		return DaoConstant.VIRTUAL_DELETE_BY_DYNAMIC_MAPPER_NAME;
	}
	
	/* (non-Javadoc)
	 * @see com.honey.mybatis.generator.AbstractField#getIsformat()
	 */
	@Override
	protected boolean getIsformat() {
	
		return false;
	}

	/* (non-Javadoc)
	 * @see com.honey.mybatis.generator.AbstractField#getJavaDoc()
	 */
	@Override
	protected String[] getJavaDoc() {
		
		return JAVA_DOC;
	}
}
